//
//  JQFYPayListTableViewCell.m
//  JQFY
//
//  Created by apple on 2017/9/12.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYPayListTableViewCell.h"

@interface JQFYPayListTableViewCell ()

@property (nonatomic ,strong) UIView *cotantView;
@property (nonatomic ,strong) UILabel *countLabel;
@property (nonatomic ,assign) NSInteger ticketCount;

@end

@implementation JQFYPayListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}

-(void) setupUI{
    _cotantView = [[UIView alloc]init];
    [self.contentView addSubview:_cotantView];
    [_cotantView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).mas_offset(10 *SCAL);
        make.height.mas_offset(22 *SCAL);
        make.right.mas_equalTo(self.contentView).mas_offset(-10 *SCAL);
    }];
    //背景
    UIImage *bgImg = [UIImage imageNamed:@"ticket_payListCell"];
    _cotantView.layer.contents = (id)bgImg.CGImage;
    _cotantView.layer.cornerRadius = 5 *SCAL;
    _cotantView.layer.masksToBounds = YES;
    //票价
    UILabel *listLabel = [[UILabel alloc] init];
    [self.cotantView addSubview:listLabel];
    listLabel.text = @"预售票 ¥ 300";
    listLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:12 *SCAL];
    listLabel.textColor = [UIColor whiteColor];
    listLabel.textAlignment = NSTextAlignmentCenter;
    [listLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.height.mas_equalTo(self.cotantView);
        make.left.mas_equalTo(self.cotantView);
        make.width.mas_offset(86 *SCAL);
    }];
    //添加
    UIView *countView = [[UIView alloc] init];
    [self.cotantView addSubview:countView];
    
    UIButton *minusBtn = [[UIButton alloc] init];
    [minusBtn setBackgroundImage:[UIImage imageNamed:@"ticket_miu"] forState:UIControlStateNormal];
    [minusBtn addTarget:self action:@selector(minusAction) forControlEvents:UIControlEventTouchUpInside];
    [countView addSubview:minusBtn];
    
    self.countLabel = [[UILabel alloc] init];
    [countView addSubview:self.countLabel];
    _countLabel.text = [NSString stringWithFormat:@"%ld",(long)_ticketCount];
    _countLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:13 *SCAL];
    _countLabel.textColor = [UIColor whiteColor];
    _countLabel.textAlignment = NSTextAlignmentCenter;

    UIButton *addBtn = [[UIButton alloc] init];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"ticket_add"] forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(addAction) forControlEvents:UIControlEventTouchUpInside];
    [countView addSubview:addBtn];
    
    [countView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.cotantView).mas_offset(-24 *SCAL);
        make.top.bottom.mas_equalTo(self.cotantView);
        make.width.mas_offset(65 *SCAL);
    }];
    [minusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.left.mas_equalTo(countView);
        make.width.height.mas_offset(15 *SCAL);
    }];
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(minusBtn.mas_right);
        make.height.mas_equalTo(countView);
        make.width.mas_offset(35 *SCAL);
    }];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.right.mas_equalTo(countView);
        make.width.height.mas_offset(15 *SCAL);
    }];
    
}

#pragma action

- (void)minusAction {
    if (self.ticketCount > 0 ) {
        self.ticketCount -= 1;
        _countLabel.text = [NSString stringWithFormat:@"%ld",(long)_ticketCount];
    }else{
        NSLog(@"点击提示");
    }
}

- (void)addAction {
    if (self.ticketCount < 100) {
        self.ticketCount += 1;
        _countLabel.text = [NSString stringWithFormat:@"%ld",(long)_ticketCount];
    }else{
        NSLog(@"点击提示");
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
